<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../assets/heima.png" alt="" />
        <span>电商管理后台</span>
      </div>
      <el-button type="info" @click="logout">Exit</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isPut ? '64px' : '200px'">
        <div @click="toCollapse">|||</div>
        <el-menu
          default-active="2"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409Eff"
          @open="handleOpen"
          @close="handleClose"
          unique-opened
          :collapse="isPut"
          :collapse-transition="false"
          router
        >
          <el-submenu
            v-for="item in menuList"
            :key="item.id"
            :index="item.id + ''"
          >
            <template slot="title">
              <i class="el-icon-user-solid"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      menuList: [],
      isPut: false
    }
  },
  created() {
    this.getMeunList()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    async getMeunList() {
      const { data: res } = await this.$http.get('menus')
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menuList = res.data
    },
    toCollapse() {
      this.isPut = !this.isPut
    }
  }
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  font-size: 20px;
  color: #fff;
  > div {
    display: flex;
    align-items: center;
    > span {
      line-height: 15px;
      padding-left: 10px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
  div {
    background-color: #4a5064;
    font-size: 10px;
    text-align: center;
    letter-spacing: 0.2em;
    color: #eee;
    line-height: 24px;
  }
}
.el-main {
  background-color: #eee;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>
